package com.designpatterns.Future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * Created by 41579 on 2017/7/18.
 */
public class main {
    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor();
        Future<Integer> future = executorService.submit(new myCallable());
        System.out.println("meddle....");
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            System.out.println(future.get()+"123");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    static class myCallable implements Callable<Integer>{

        @Override
        public Integer call() throws Exception {
            System.out.println("begin...");
            TimeUnit.SECONDS.sleep(2);
            System.out.println("begin_end...");
            return 3;
        }
    }
}
